import Message from "element-ui/packages/message/src/main";
import * as loginAPI from "../../api/loginAPI";

const loginStorage = {
    state: {},
    mutations: {},
    actions: {
        login: async ({commit}, loginDto) => {
            try {
                let res = await loginAPI.loginByLoginFormAPI(loginDto);
                if (!res) {
                    Message({
                        message: "用户名或密码错误",
                        type: "error"
                    });
                }
                return res;
            } catch (e) {
                return {code: 500};
            }
        },
        logOut: async ({commit}) => {
            try {
                let res = await loginAPI.logOutAPI();
                if (!res) {
                    Message({
                        message: "登出失败",
                        type: "error"
                    });
                }
                return res;
            } catch (e) {
                return {code: 500};
            }
        },
        getOneCaptcha: async ({commit}) => {
            try {
                let res = await loginAPI.getOneCaptchaAPI();
                if (!res) {
                    Message({
                        message: "登出失败",
                        type: "error"
                    });
                }
                return res;
            } catch (e) {
                return {code: 500};
            }
        }
    }

};

export default loginStorage;